<?php
include_once("./function.php");
$sql="select * from ts_product_cate";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if((mysqli_num_rows($res))!=false)
	{
		$pro=array();
		while($list=mysqli_fetch_assoc($res))
		{
			$pro[]=$list;
		}
		//print_r($pro);die;//Array ( [0] => Array ( [pc_id] => 1 [pc_fid] => 0 [pc_name] => 服装 [pc_level] => 1 [pc_ifshow] => show )
	}
}
//无线分类
function card($arr,$pc_fid)
{
	static $new=array();
	foreach($arr as $v)
	{
		if($v['pc_fid']==$pc_fid)
		{
			$new[]=$v;
			card($arr,$v['pc_id']);
		}
	}
	return $new;
}
$pro=card($pro,0);
if(isset($_GET["id"])){
	$sql="select * from ts_product_cate where pc_id=".$_GET['id'];
	$res=mysqli_query($link,$sql);
	if(is_object($res))
	{
		if(mysqli_num_rows($res)>0)
		{
			$one=mysqli_fetch_assoc($res);
		}
		//print_r($one);die;//Array ( [pc_id] => 4 [pc_fid] => 2 [pc_name] => 西服 [pc_level] => 3 [pc_ifshow] => show )
	}
	$type=0;
	$sql="select * from ts_product_cate where pc_fid=".$one['pc_id'];
	$res=mysqli_query($link,$sql);
	if(is_object($res))
	{
		if(mysqli_num_rows($res)>0)
		{
			$type=1;
		}
	}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主体部分</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<form action="do_product_cate_edit.php" method="get">
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>修改商品分类</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>
		<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;">
			 <tr>
				<td width="100px;">上级分类:</td>
				<td>
			<select name="id">
					<option value="0" <?php if($type==1){?> disabled <?php }?> selected>顶级分类</option>
					<?php foreach($pro as $v){?>
						<option value="<?=$v['pc_id']?>"
						<?php if($one['pc_fid']==$v['pc_id']){echo "selected";}?>
					<?php if($type==1||$v['pc_id']==$one['pc_id']){?>disabled
					<?php }?>
					><?=str_repeat("&nbsp;",3*($v['pc_level']-1)).$v['pc_name']?></option>
					<?php }?>
			</select>
				</td>
			  </tr>
			   <tr>
				 <td>分类名称:</td>
				 <td><input type="text" name="pname" value="<?=$one['pc_name']?>"/></td>
			   </tr>
			   <tr>
				 <td>首页是否显示</td>
				 <td><input type="radio" name="show" value="show" checked>显示 <input type="radio" name="show" value="noshow"> 不显示</td>
			   </tr>
			   <tr>
				 <td colspan="2" align="center" height="40px">
				 <input type="hidden" name="cid" value="<?=$one['pc_id']?>" />
					<input type="submit" name="sub" value="修改"/>
				 </td>
			   </tr>
		</table>
	</td>
  </tr>
</table>
</form>
</body>
</html>